﻿   var messageBanner;

    // Office JS 和 JQuery 准备就绪时初始化
    Office.onReady(() => {
        $(() => {
            var element = document.querySelector('.MessageBanner');
            messageBanner = new components.MessageBanner(element);
            messageBanner.hideBanner();

            $('#get-data-from-selection').on('click',getDataFromSelection);
        });
    });

    // 从当前选择的文档内容中读取数据并显示通知
    async function getDataFromSelection() {
        try {
            await Excel.run(async (context) => {
                var range = context.workbook.getSelectedRange();
                range.load("text");
                await context.sync();
                const textValues = range.text.toString();
                showNotification('The selected text is:', '"' + textValues + '"');
            });
    
        } catch (error) {
            showNotification('Error:', error.message);
        }
    }
   
    // 用于显示通知的帮助程序函数
    function showNotification(header, content) {
        $("#notificationHeader").text(header);
        $("#notificationBody").text(content);
        messageBanner.showBanner();
        messageBanner.toggleExpansion();
    }
